<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
  <style>
    .container {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }

    @keyframes shake {
      0% {
        opacity: 0;
        font-size: 14px;
      }

      50% {
        opacity: 0.3;
        font-size: 60px;
      }

      100% {
        opacity: 1;
        font-size: 40px;
      }
    }

    .v-enter-active,
    .v-leave-active {
      animation: shake 3s linear;
    } 
  </style>
</head>

<body>
  <div id="root"></div>
  <script>
    /* 
      1. 多个元素/组件切换动画也可以通过transition组件实现
      2. type属性
        - out-in 先隐藏旧元素，再显示新元素，默认同时进行
      3. appear
        - 在元素首次渲染时就执行动画
      4. 组件的切换动画
      - 方式一 v-if/v-show
      - 方式二 动态组件component+is
    */
    const app = Vue.createApp({
      template: `
      <div class="container">
        <transition mode="out-in" appear>
          <div v-if="isShow">Hello World</div>
          <div v-if="!isShow">Hello Vue3</div>
        </transition>
        <button @click="isShow = !isShow">切换</button>
      </div>
    `,
      data() {
        return {
          isShow: false
        }
      }
    })
    const vm = app.mount('#root');

  </script>
</body>

</html>